﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FCTC_Web.Models;
using FCTC_Web.DAL;
using FCTC_Web.Utilities;
using DAL;

namespace FCTC_Web.Controllers
{
    public class SessionArrangementController : Controller
    {
        //[Authorize]
        public ViewResult Index(int? pageId)
        {
            return View("Index", Pager10.Ins.GetPage<SessionArrangement>(pageId));
        }

        [HttpPost]
        public ActionResult Edit(SessionArrangement sessionArrangement)
        {

            if (ModelState.IsValid)
            {
                CH.Edit<SessionArrangement>(sessionArrangement);
                var pageId = Pager10.Ins.GetPageId<SessionArrangement>(sessionArrangement.ID);
                return RedirectToAction("Index", new { pageId = pageId });
            }
            return View(sessionArrangement);
        }


        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            CH.Delete<SessionArrangement>(id);
            return RedirectToAction("Index");
        }

        [HttpPost]
        public ActionResult Create(SessionArrangement sessionArrangement)
        {
            if (ModelState.IsValid)
            {
                sessionArrangement.UpdateTime = DateTime.Now;
                sessionArrangement.UpdatedUser = HttpContext.User.Identity.Name;
                CH.Create<SessionArrangement>(sessionArrangement);
                var pageId = Pager10.Ins.GetPageId<SessionArrangement>(sessionArrangement.ID);
                return RedirectToAction("Index", new { pageId = pageId });
            }
            return View(sessionArrangement);
        }

        public ViewResult Details(int? id)
        {
            SessionArrangement sessionArrangement = CH.GetDataById<SessionArrangement>(id);
            return View(sessionArrangement);
        }

        public ActionResult Create()
        {
            return View();
        }

        public ActionResult Edit(int? id)
        {
            return View(CH.GetDataById<SessionArrangement>(id));
        }



        public ActionResult Delete(int? id)
        {
            SessionArrangement sessionArrangement = CH.GetDataById<SessionArrangement>(id);
            return View(sessionArrangement);
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }
    }
}